package top.caoayu.common.validetor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import top.caoayu.base.controller.ArticleController;
import top.caoayu.base.entity.Article;
import top.caoayu.base.mapper.ArticleMapper;
import top.caoayu.common.annatation.AritcleTitleUnique;
import top.caoayu.common.annatation.CommonValidate;

import javax.annotation.Resource;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class AritleTitleUniqueValidator implements ConstraintValidator<AritcleTitleUnique, String> {
    @Resource
    private ArticleMapper articleMapper;
    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("title",s);
        return articleMapper.selectCount(queryWrapper) <= 0;
    }
}
